<?php
	include_once 'isLogin.php';
	include_once 'model/upload.class.php';
	
	$table_name = "banklogo";
	
	if($_POST['submit']){
		//编辑状态先获得原内容
		if($_GET['id']!=false){
			$old = $commonc->getInfo($table_name,$_GET['id'],'logo,file');
			$logo = $old['logo'];
		}
		
		//上传图片，生成缩略图
		if($_FILES['logo']['name']!=''){
			//设置路径
			$folder="../admin/upload/bank/";
			$annexFolder = $folder."large/";
			$middleFolder = $folder."middle/";
			$smallFolder = $folder."small/";
			//删除旧图
			@unlink($annexFolder.$logo);
			@unlink($middleFolder.$logo);
			@unlink($smallFolder.$logo);
			//上传新图
			$upimg = new uploadImg();
			$logo = $upimg->upLoad('logo',$annexFolder);
			//中图
			$upimg->smallImg($annexFolder.$logo,$middleFolder);
			//小图
			$upimg->smallImg($annexFolder.$logo,$smallFolder);
		}
		
		//上传文件
		
		//插入数据库
		$data = array('name'=>$_POST['name'],'logo'=>$logo);
		if($_GET['id']!=false){
			$commonc->update($table_name,$data,"id='".$_GET['id']."'");
			$href = $_basename.'?id='.$_GET['id'];
		}else{
			$commonc->insert($table_name,$data);
			$href='banklogo_add.php';
			$id = $commonc->insert_id();
			//$data = array('sort'=>$id);
			//$commonc->update($table_name, $data, "id='".$id."'");
		}
		echo $commonc->submitAlert('成功',$href);
	}
	
	//获得数据
	if($_GET['id']!=false){
		$row=$commonc->getInfo($table_name,$_GET['id']);
		$smarty->assign('row',$row);
	}
	
	$smarty->display($_filename.".html");
?>